import {
  Table,
  Column,
  Model,
  CreatedAt,
  UpdatedAt,
  ForeignKey,
  BelongsTo,
  HasMany,
} from 'sequelize-typescript';
import { Audit } from 'src/audit/audit.entity';
import { User } from 'src/user/user.entity';
import { Video } from 'src/video/video.entity';

@Table({
  tableName: 'project',
})
export class Project extends Model<Project> {
  @Column({
    primaryKey: true,
  })
  id: number;

  @Column
  uuid: string;

  @Column
  name: string;

  @Column
  introduction: string;

  @Column({ field: 'upload_time' })
  uploadTime: Date;

  @ForeignKey(() => User)
  @Column({ field: 'fk_user' })
  FKUser: number;

  @ForeignKey(() => Audit)
  @Column({ field: 'fk_audit' })
  FKAudit: number;

  @Column({ field: 'project_type' })
  projectType: number;

  @CreatedAt
  @Column({ field: 'created_at' })
  createdAt: Date;

  @UpdatedAt
  @Column({ field: 'updated_at' })
  updatedAt: Date;

  @BelongsTo(() => User)
  user: User;

  @BelongsTo(() => Audit)
  audit: Audit;

  @HasMany(() => Video)
  videos: Video[];
}
